#ifndef __DEINTERLEAVE_IO_H__
#define __DEINTERLEAVE_IO_H__ 1

#include "sample_io.h"
#include "codec.h"

class CDeinterleaveIO : public ISampleIO
{
public:
	CDeinterleaveIO(ISampleIO *pIO);
	virtual ~CDeinterleaveIO();

	/* START methods inherited by ISampleIO */
	virtual int init(CPropertiesReader *pConfig);
	virtual int destroy();

	virtual int read(void** pData, EAction& pAction, int pTimeout = 1000);
	virtual int write(void* pData, const EAction& pAction, int pLength);

	virtual NAudioFormats::SStreamInfo getStreamInfo();
	/* END methods inherited by ISampleIO */

private:
	ISampleIO *mIO;
	void* mReadInterleavedData;
	int mReadInterleavedLength;
	EAction mReadInterleavedAction;
	char* mReadByteBuf;
	int mReadByteCount;

	void* mWriteInterleavedData;
	int mWriteInterleavedLength;
	EAction mWriteLastAction;
	char* mWriteByteBuf;
	int mWriteByteCount;

	CDeinterleaveIO(const CDeinterleaveIO& );
	CDeinterleaveIO& operator=(const CDeinterleaveIO& );

	void* getReadByteBuffer(int pByteLength);
	void* getWriteByteBuffer(int pByteLength);
	int deinterleave(void* pOutBuffer, int pOutLength, void* pInBuffer, int pInLength, bool pEmbedSamples);
	int interleave(void* pOutBuffer, int pOutLength, void* pInBuffer, int pInLength, bool pEmbedSamples);
};

#endif /* __DEINTERLEAVE_IO_H__ */

